# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  
  # 保存错误日志
  # 2012.08.03
  if ENV['RAILS_ENV'] != "development"
    rescue_from Exception do |exception|
      logger.info "[Rescue From] #{exception.class}"
      logger.info "[Exception Name] #{exception.message}"
      logger.info "[URL] #{request.url}"
      logger.info exception.backtrace.join("\n")
      params.merge!({:user_agent => request.env["HTTP_USER_AGENT"]})
      case exception
        when ActionView::MissingTemplate
        return (render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Error")
      else
        return rescue_action_in_public(exception)
      end
      render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" 
    end
  end    
  
end
